import logging

from datastore.resource import *
from datastore.uri import *
from runtime.service import *

class Crud(Service):
    """
    A Simple service to log a message and generate a HTML page.
    """

    def cb_start(self, uri, action, res):
        """
        We will need a http_service enhancement to allow a number of different
        templates to be specified. view resource will be default, but we must
        be able to request the update/create template. 
        OR we would have conditional text in a single template.
        
        What do we need:
        - data resource type. data resources will all be of this type.
        
        - view list of resources template, with buttons to add new resources,
        update, or delete an existing resource, and a link to view a resource.
        
        - view list of resources template must be able to display a message:
          - delete/update/create successful.
        
        - create/update template.
        
        - view resource template.
                
        - queue for the delete, create and update POSTs.
          -> process callback (exists, get, put/update)
            - form button data will tell what to do.
        
        - GET to view list. - process (use index service?).
          -> callback
        
        - GET to view a resource. - let http_service fetch a real resource.
        """
        pass
            
        # Add this UI to the examples index page
        index_res = Resource(type='term:base/services/index/entry')
        index_res.dc_title("crud - create, read, update, delete resource")
        index_res.index = Uri('external:examples')
        index_res.uri = res.options.url
        self.spaces.put(Uri('internal:base/index/entries/'), index_res)
